package com.raven.craft.code.generator.mysql.schema.puml;

import com.raven.craft.code.generator.IGenerator;
import com.raven.craft.code.generator.common.constant.FileSuffix;
import com.raven.craft.code.generator.common.file.HbsFile;
import com.raven.craft.code.generator.common.file.metadata.FileMetadata;
import com.raven.craft.code.generator.config.MysqlContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @author raven
 * @date 2020/08/25
 **/
@Slf4j
public class PumlSchemaGenerator implements IGenerator {

    private final MysqlContext context;

    private final PumlSchemaProperties pumlProperties;

    public PumlSchemaGenerator(MysqlContext context, PumlSchemaProperties properties) {
        this.context = context;
        this.pumlProperties = properties;
    }

    private static HbsFile createPumlSchemaFile(MysqlContext context, PumlSchemaProperties properties) {
        FileMetadata metadata = new FileMetadata(context.getDatabase(), FileSuffix.PUML, properties.getTargetDir());
        PumlSchemaVo vo = new PumlSchemaVo(context, properties);
        return new HbsFile(metadata, properties.getTemplatePath(), vo);
    }

    @Override
    public void generate() {
        log.info("begin to generate puml schema file");
        createPumlSchemaFile(context, pumlProperties).output();
    }
}
